package ru.usu.gv.core;

import ru.usu.gv.styles.StyleFacade;
import ru.usu.gv.utils.Pair;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author spupyrev
 * 10.11.2009
 */
public class I18nService
{
	private static final String GV_BUNDLE = "GV_I18n";
	private static final I18nService instance = new I18nService();
	private ResourceBundle resourceBundle;

	private I18nService()
	{
		String defaultLocale = StyleFacade.getLocale();
		resourceBundle = ResourceBundle.getBundle(GV_BUNDLE, new Locale(defaultLocale));
	}

	public static void setLocale(String locale)
	{
		instance.resourceBundle = ResourceBundle.getBundle(GV_BUNDLE, new Locale(locale));
	}

	public static String getLocale()
	{
		return instance.resourceBundle.getLocale().getLanguage();
	}

	public static List<Pair<String, String>> listLocales()
	{
		List<Pair<String, String>> locales = new ArrayList();
		locales.add(new Pair("English", "en"));
		locales.add(new Pair("Russian", "ru"));
		return locales;
	}

	public static String get(String key)
	{
		return instance.resourceBundle.getString(key);
	}
}
